package logic

import (
	"context"
	"selection-inventory/application/applet/internal/model"

	"selection-inventory/application/applet/internal/svc"
	"selection-inventory/application/applet/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type DeleteCommodityLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDeleteCommodityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteCommodityLogic {
	return &DeleteCommodityLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DeleteCommodityLogic) DeleteCommodity(req *types.DeleteRequest) (resp bool, err error) {
	res := l.svcCtx.DB.Delete(&model.Commodity{
		Id: req.Id,
	})
	if res.Error != nil {
		return false, err
	}
	return res.RowsAffected > 0, nil
}
